<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1" name="viewport">
    <title>mybatis-generator-自动生成代码</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">自动生成代码</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item"><a href="" th:href="@{/index}">首页</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">功能菜单</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" th:href="@{/index}">生成代码</a></dd>
                        <dd><a href="javascript:;" th:href="@{/list}">下载列表</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>

    <div class="layui-body">
        <blockquote class="layui-elem-quote layui-text" style="margin-top: 10px">
            下载列表
        </blockquote>

        <fieldset class="layui-elem-field" style="margin: 20px">
            <legend style="color: red">下载列表</legend>
            <div class="layui-field-box">
                <table id="downloadTable" lay-filter="downloadTable"></table>
                <script id="barDownload" type="text/html">
                    <a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
                </script>
            </div>
        </fieldset>

    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © mybatis-generator-自动生成代码
    </div>
</div>
<script th:src="@{layui/layui.js}"></script>
<script th:inline="javascript">

    var queryUrl = /*[[@{/dataCodeInfo/query}]]*/ '';

    var downloadUrl = /*[[@{/dataCodeInfo/download}]]*/ '';

    //JavaScript代码区域
    layui.use(['form', 'layedit', 'laydate', 'upload', 'element', 'table'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , element = layui.element
            , table = layui.table
            , $ = layui.jquery
            , upload = layui.upload;

        //第一个实例
        table.render({
            elem: '#downloadTable'
            , height: 312
            , url: queryUrl //数据接口
            , page: false //开启分页
            , cols: [
                [ //表头
                    {field: 'id', title: 'ID', width: 300, sort: true, fixed: 'left'}
                    , {field: 'folder', title: '文件夹名称'}
                    , {field: 'createTime', title: '创建时间', width: 300}
                    , {fixed: 'right', title: '操作', width: 150, align: 'center', toolbar: '#barDownload'} //这里的toolbar值是模板元素的选择器
                ]
            ]
        });


        //监听工具条
        table.on('tool(downloadTable)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'download') { //查看
                var id = data.id;
                window.location.href = downloadUrl + "?id=" + id;
            }
        });

    })
</script>
</body>
</html>